package com.yb0os1.controller.user;

import com.yb0os1.dto.ShoppingCartDTO;
import com.yb0os1.entity.ShoppingCart;
import com.yb0os1.result.Result;
import com.yb0os1.serve.ShoppingCartServe;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Tag(name = "用户购物车相关操作")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartServe shoppingCartServe;

    @Operation(summary = "向购物车添加")
    @PostMapping("/add")
    public Result<String> addToShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartServe.addToShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @Operation(summary = "查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getShoppingCart(){
        return Result.success(shoppingCartServe.getShoppingCart());
    }

    @Operation(summary = "删除单个商品")
    @PostMapping("/sub")
    public Result subOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartServe.deleteOne(shoppingCartDTO);
        return Result.success();
    }

    @Operation(summary = "删除所有")
    @DeleteMapping("/clean")
    public Result cleanAll(){
        shoppingCartServe.clean();
        return Result.success();
    }
 }
